home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / GRAPH_FO / (GRAPH / GRAPH_SO / GRLIST.C < prev    next >
Text File  |  1991-02-12  |  5KB  |  201 lines

  1. /******************************************************************************
  2.     GrList.c
  3.         Graph methods in Object C.
  4.  
  5.     SUPERCLASS = CList
  6.  
  7.     Copyright ⌐ 1991 Maarten Meijer. All rights reserved.
  8.         CIS 100016,1764; FidoNet 2:512/114
  9. *******************************************************************************/
  10.  
  11.  
  12. #include "GrList.h"
  13.  
  14. /******************************************************************************
  15.     IGrList
  16.  
  17.         Initialize GrList
  18. *******************************************************************************/
  19. void
  20. GrList::IGrList() {
  21.     inherited::IList();        /* CList */
  22.     }
  23.  
  24. /******************************************************************************
  25.     Draw
  26.         Draw all GrNodes inside an area, being inside is determined by the
  27.         GrNode method NodeInRect().
  28. *******************************************************************************/
  29. static void                    /* NOT a method !! */
  30. _DrawAllRect(GrNode *theNode, Rect *area) {
  31.     Point    loc;
  32.  
  33.  
  34.     if(theNode->NodeInRect(area)) {
  35.         theNode->Draw();
  36.         theNode->SetRegion();
  37.         }
  38. /*
  39.      should region also be set when outside the drawing area or does
  40.     the region need to be set every time the node is drawn?
  41.  */
  42.     }
  43.  
  44. void
  45. GrList::Draw(Rect *area) {
  46.     CCluster::DoForEach1(_DrawAllRect, (long)area);
  47.     }
  48.  
  49. /******************************************************************************
  50.     _Draw
  51.  
  52.         Draw all irrespective of area without erasing.
  53.         Used for edgeList drawing, but not functioning well.
  54. *******************************************************************************/
  55. static void                    /* NOT a method !! */
  56. _DrawAll(GrNode *this) {
  57.     this->_Draw();
  58.     }
  59.  
  60. void
  61. GrList::_Draw() {
  62.     CCluster::DoForEach(_DrawAll);
  63.     }
  64.  
  65.  
  66. static void                    /* NOT a method !! */
  67. _SelectAll(GrNode *this, Rect *r) {
  68.     if(this->NodeInRect(r)) {        /* Not exact, see IM I-185 */
  69.         this->Select();
  70.         this->Draw();
  71.         }
  72.     }
  73.  
  74. void
  75. GrList::Select(Rect *r) {
  76.     CCluster::DoForEach1(_SelectAll, (long)r);
  77.     }
  78.  
  79. static void                    /* NOT a method !! */
  80. _DeselectAll(GrNode *this) {
  81.     if(this->Selected()) {
  82.         this->Deselect();
  83.         this->Draw();
  84.         }
  85.     }
  86.  
  87. void
  88. GrList::Deselect() {
  89.     CCluster::DoForEach(_DeselectAll);
  90.     }
  91.  
  92.  
  93. static long    count;
  94.  
  95. static void
  96. _CountSelected(GrNode *this) {
  97.     if(this->Selected())
  98.         count++;
  99.     }
  100.  
  101. long
  102. GrList::CountSelected() {
  103.     count = 0L;
  104.     CCluster::DoForEach(_CountSelected);
  105.     return    count;
  106.     }
  107.  
  108. static    Boolean
  109. _Selected(GrNode *this) {
  110.     return (this->Selected());
  111.     }
  112.  
  113. GrNode *
  114. GrList::GetSelected() {
  115.     GrNode    *found;
  116.     found = (GrNode *)CList::FirstSuccess(_Selected);
  117.     if(found != NULL)
  118.         SendBack(found);    /* so you can loop thru the whole list */
  119.     return found;
  120.     }
  121.  
  122. /******************************************************************************
  123.     AddNode & RemoveNode
  124.  
  125.         Adding and removing nodes from the GrList.
  126. *******************************************************************************/
  127. void
  128. GrList::AddNode(GrNode *which) {
  129.     inherited::Append(which);    /* Clist */
  130.     }
  131.  
  132. void
  133. GrList::RemoveNode(GrNode *which) {
  134.     CList::Remove(which);    /* CList remove from list */
  135.     which->Dispose();            /* and dispose of it */
  136.     }
  137.  
  138. /******************************************************************************
  139.     FindNode
  140.  
  141.         Find the node that was clicked on.
  142. *******************************************************************************/
  143. static Boolean                    /* NOT a method !! */
  144. _FindNode(GrNode *this, Point where) {
  145.     if(this->PtInNode(where))
  146.         return true;
  147.     else
  148.         return false;
  149.     }
  150.  
  151. GrNode *
  152. GrList::FindNode(Point where) {
  153.     GrNode *node;
  154.     node = (GrNode *)CList::LastSuccess1(_FindNode, *(long *)&where);
  155.     return node;
  156.     }
  157.  
  158. /******************************************************************************
  159.     FindIncident
  160.  
  161.         Find connected edges to a vertex, unable to loop thru all, this
  162.         would be possible with a move to back/front alogoritm.
  163. *******************************************************************************/
  164. static    Boolean                    /* NOT a method !! */
  165. _FindIncident(GrNode *this, GrNode *which) {
  166.     return this->Incident(which);
  167.     }
  168.  
  169. GrNode *
  170. GrList::FindIncident(GrNode *which) {
  171.     return (GrNode *)CList::FirstSuccess1(_FindIncident,
  172.             (long)which);
  173.     }
  174.  
  175. /******************************************************************************
  176.     SpanningRect
  177.  
  178.         Find the rect that encloses all edges connected to a vertex,
  179.         and edges going thru the area vacated by the vertex.
  180. *******************************************************************************/
  181. static Rect vertexRect,        /* the rect of the vertex */
  182.             resultRect;        /* the rect enclosing all edges */
  183.  
  184. static void
  185. _SpanningRect(GrNode *this, GrNode *which) {
  186.     Rect    edgeRect;    /* the rect of each edge */
  187.  
  188.     if( this->Incident(which) ) {
  189.         this->GetRect(&edgeRect);
  190.         UnionRect(&edgeRect, &resultRect, &resultRect);
  191.         }
  192.     }
  193.  
  194. void
  195. GrList::SpanningRect(GrNode *which, Rect *rect) {
  196.  
  197.     which->GetRect(&resultRect);
  198.     CCluster::DoForEach1(_SpanningRect, (long)which);
  199.     *rect = resultRect;
  200.     }
  201.